<template>
  <div class="newModel">
    <!-- 用户类型 holderType-->
    <div>
      <div class="topSec">
        <div>
          <div class="form-head-name">投保人信息</div>
          <div class="tit_tips">购买本保险，交保费的人</div>
        </div>
        <!-- <div class="flex_ac" v-if="!disEditFields">
          <MsImgIcon
            name="abook_g"
            class="ml20"
            @click.native="openDirectory()"
            v-if="customerInfos === '1'"
          />
          <MsImgIcon
            name="photo"
            class="ml20"
            @click.native="showSheet = true"
          />
        </div> -->
      </div>
      <!-- 姓名 name-->
      <van-field
        label="姓名"
        :input-align="inputAlign"
        class="refname"
        :class="{ disEditModel: disEditFields }"
        v-model="userInfo.name"
        clearable
        placeholder="请输入"
        @blur="validInfo('name')"
        @focus="tipsInfo.name = ''"
        :error="tipsInfo.name !== ''"
      >
        <MsImgIcon
          name="abook_g"
          size="24"
          slot="button"
          @click.native="openDirectory()"
          v-if="customerInfos === '1'"
        />
      </van-field>
      <van-field
        label="证件类型"
        :input-align="inputAlign"
        class="refidType"
        :class="{ disEditModel: disEditFields }"
        @click="
          !disEditFields &&
            showPopAction('picker', 'idType', idTypeList, userInfo.idType)
        "
        @focus="tipsInfo.idType = ''"
        :value="userInfo.idName"
        readonly
        placeholder="请选择"
        :error="tipsInfo.idType !== ''"
        v-if="infoReg.hasOwnProperty('idType')"
      >
        <span
          class="ms-row-icon"
          slot="right-icon"
          v-if="!disEditFields && idTypeList.length > 1"
        ></span>
      </van-field>
      <!-- 证件号码 idNum-->
      <van-field
        class="refidNum"
        :class="{ disEditModel: disEditFields }"
        label="证件号码"
        :input-align="inputAlign"
        v-model="userInfo.idNum"
        clearable
        placeholder="请输入"
        @click="tipsInfo.idNum = ''"
        @focus="foI = true"
        @blur="
          foI = false;
          validInfo('idNum');
        "
        :error="tipsInfo.idNum !== ''"
      >
        <MsImgIcon
          name="camera_g"
          size="24"
          slot="button"
          @click.native="showSheet = true"
        />
      </van-field>
      <!-- 性别 -->
      <van-field
        label="性别"
        :input-align="inputAlign"
        class="refsex"
        :class="{ disEditModel: disEditFields }"
      >
        <div slot="input">
          <span class="btn_text thin-border" v-if="disabledSex">
            {{ userInfo.sex == "1" ? "女" : "男" }}
          </span>
          <MsRadios
            v-else
            :curVal="userInfo.sex"
            :arrList="sexList"
            type="sex"
            @change="changeMsRadio"
          />
        </div>
      </van-field>
      <van-field
        label="出生日期"
        placeholder="请选择"
        :input-align="inputAlign"
        class="refbirthDate"
        :class="{ disEditModel: disEditFields }"
        @click-input="showPopAction('date', 'birthDate', [])"
        readonly
        :disabled="disEditFields"
      >
        <div class="age-box" slot="input">
          <span v-if="userInfo.birthDate"
            >{{ userInfo.birthDate }} ( {{ ageVal }}周岁 )
          </span>
          <span v-else style="color: #999">请选择</span>
        </div>
        <span class="ms-row-icon" slot="right-icon" v-if="!disabledSex"></span>
      </van-field>
      <div :class="slPreWarn ? 'disabledForm' : ''" @click="noAuthHandle">
        <!-- 证件有效期 -->
        <van-field
          v-if="infoReg.hasOwnProperty('validDateEnd')"
          class="set_flex1 refvalidDateEnd"
          :input-align="inputAlign"
        >
          <div slot="label" class="userSelect">
            <span>证件有效期</span>
            <FieldDescMode field="validDateEnd" />
          </div>
          <div slot="input">
            <MsRadios
              :curVal="longTime == userInfo.validDateEnd"
              :arrList="dateEndList"
              type="validDateEnd"
              @change="changeMsRadio"
            />
          </div>
        </van-field>
        <van-field
          label="有效期起期"
          :input-align="inputAlign"
          class="refvalidDate"
          v-if="infoReg.hasOwnProperty('validDate')"
          @click="showPopAction('date', 'validDate', [])"
          @focus="tipsInfo.validDate = ''"
          :value="userInfo.validDate"
          readonly
          placeholder="请选择"
          :error="tipsInfo.validDate !== ''"
        >
          <span class="ms-row-icon" slot="right-icon"></span>
        </van-field>
        <van-field
          label="有效期止期"
          :input-align="inputAlign"
          class="refvalidDateEnd"
          v-if="
            infoReg.hasOwnProperty('validDateEnd') &&
            (longTime !== userInfo.validDateEnd || !showLonger)
          "
          @click-input="showPopAction('date', 'validDateEnd', [])"
          :value="
            userInfo.validDateEnd == longTime ? '长期' : userInfo.validDateEnd
          "
          readonly
          placeholder="请选择"
          :error="tipsInfo.validDateEnd !== ''"
          @focus="tipsInfo.validDateEnd = ''"
        >
          <span
            class="ms-row-icon"
            slot="right-icon"
            v-if="!validDateDisabled"
          ></span>
        </van-field>
        <!-- 现居地址 areaName   -->
        <van-field
          :input-align="inputAlign"
          class="refareaName"
          v-if="infoReg.hasOwnProperty('areaName')"
          @click="showPopAction('address', 'areaName', [])"
          :value="userInfo.areaName"
          label="现居地址"
          type="textarea"
          rows="1"
          autosize
          readonly
          placeholder="请选择"
          @focus="tipsInfo.areaName = ''"
          :error="tipsInfo.areaName !== ''"
        >
          <span class="ms-row-icon" slot="right-icon"></span>
        </van-field>
        <van-field
          :input-align="inputAlign"
          class="refpermanentAddress"
          v-if="infoReg.hasOwnProperty('permanentAddress')"
          v-model="userInfo.permanentAddress"
          label="详细地址"
          type="textarea"
          rows="1"
          maxlength="30"
          autosize
          clearable
          :placeholder="`必须包含:${detailAddrRule}`"
          @input="tipsInfo.permanentAddress = ''"
          @focus="tipsInfo.permanentAddress = ''"
          @blur="validInfo('permanentAddress')"
          :error="tipsInfo.permanentAddress !== ''"
        />
        <van-field
          label="国籍"
          :input-align="inputAlign"
          class="refnationality"
          v-if="infoReg.hasOwnProperty('nationality')"
          @click="
            tipsInfo.nationality = '';
            showPopAction(
              'picker',
              'nationality',
              nationList,
              userInfo.nationality
            );
          "
          :value="userInfo.nationalityName"
          readonly
          placeholder="请选择"
          :error="tipsInfo.nationality !== ''"
        >
          <span
            class="ms-row-icon"
            slot="right-icon"
            v-if="nationList.length > 1"
          ></span>
        </van-field>
        <van-field
          class="refphone"
          :input-align="inputAlign"
          v-if="infoReg.hasOwnProperty('phone')"
          v-model="cpPhoneNum"
          label="手机号码"
          type="number"
          :maxlength="foI2 ? '11' : '13'"
          clearable
          placeholder="请输入"
          @focus="
            foI2 = true;
            tipsInfo.phone = '';
          "
          @blur="
            foI2 = false;
            checkSmsCodeStauts();
          "
          :error="tipsInfo.phone !== ''"
        >
        </van-field>
        <!--注意获取验证吗的时机-->
        <van-field
          class="phone_code_md"
          v-if="infoReg.hasOwnProperty('validCode')"
          :input-align="inputAlign"
          v-model="userInfo.validCode"
          label="短信验证码"
          type="number"
          maxlength="6"
          clearable
          placeholder="请输入"
          @blur="checkSmsCodeStauts()"
        >
          <SmsCodeBtn
            slot="button"
            ref="smsCodeRef"
            :phoneNum="userInfo.phone"
          />
        </van-field>
        <van-field
          label="职业名称"
          :input-align="inputAlign"
          class="refoccupationCode"
          :class="{ disEditModel: disEditFields }"
          :value="userInfo.occupationCodeName"
          v-if="infoReg.hasOwnProperty('occupationCode')"
          @click="
            showPopAction('job', 'occupationCode', []);
            tipsInfo.occupationCode = '';
          "
          type="textarea"
          rows="1"
          autosize
          readonly
          placeholder="请选择"
          :error="tipsInfo.occupationCode !== ''"
        >
          <span class="ms-row-icon" slot="right-icon"></span>
        </van-field>
        <van-field
          label="工作单位"
          :input-align="inputAlign"
          class="refgrpName"
          v-if="infoReg.hasOwnProperty('grpName')"
          v-model="userInfo.grpName"
          type="textarea"
          maxlength="30"
          rows="1"
          autosize
          clearable
          placeholder="请输入"
          @focus="tipsInfo.grpName = ''"
          :error="tipsInfo.grpName !== ''"
        />
        <van-field
          label="工作内容"
          :input-align="inputAlign"
          class="refjobContent"
          v-if="infoReg.hasOwnProperty('jobContent')"
          v-model="userInfo.jobContent"
          type="textarea"
          maxlength="30"
          rows="1"
          autosize
          clearable
          placeholder="请输入"
          @focus="tipsInfo.jobContent = ''"
          :error="tipsInfo.jobContent !== ''"
        />
        <van-field
          label="兼职"
          :input-align="inputAlign"
          class="refpartTimeJob"
          v-if="infoReg.hasOwnProperty('partTimeJob')"
          v-model="userInfo.partTimeJob"
          type="textarea"
          maxlength="30"
          rows="1"
          autosize
          clearable
          placeholder="请输入"
          @focus="tipsInfo.partTimeJob = ''"
          :error="tipsInfo.partTimeJob !== ''"
        />
        <van-field
          class="refincome"
          :input-align="inputAlign"
          label="年收入"
          v-if="infoReg.hasOwnProperty('income')"
          :value="userInfo.income"
          type="number"
          placeholder="请输入"
          @input="(e) => (userInfo.income = money(e))"
          @focus="tipsInfo.income = ''"
          @blur="testIncom"
          :error="tipsInfo.income !== ''"
        >
          <template #button>
            <span class="field_unit">万元</span>
          </template>
        </van-field>
        <van-field
          class="refheight"
          v-model="userInfo.height"
          :input-align="inputAlign"
          v-if="infoReg.hasOwnProperty('height')"
          maxlength="3"
          :formatter="formatter"
          clearable
          label="身高（CM）"
          type="digit"
          placeholder="请输入"
          @focus="tipsInfo.height = ''"
          :error="tipsInfo.height !== ''"
          @blur="testBMI('height')"
        >
          <template #button>
            <span class="field_unit">厘米</span>
          </template>
        </van-field>
        <van-field
          v-model="userInfo.weight"
          v-if="infoReg.hasOwnProperty('weight')"
          label="体重（KG）"
          maxlength="3"
          clearable
          :input-align="inputAlign"
          type="number"
          placeholder="请输入"
          @focus="tipsInfo.weight = ''"
          :formatter="formatter"
          @blur="testBMI('weight')"
          :error="tipsInfo.weight !== ''"
        >
          <template #button>
            <span class="field_unit">公斤</span>
          </template>
        </van-field>
        <van-field
          :input-align="inputAlign"
          class="refnationCode"
          v-if="infoReg.hasOwnProperty('nationCode')"
          :value="userInfo.nationName"
          label="民族"
          @click="showPopAction('picker', 'nationCode', [])"
          readonly
          placeholder="请选择"
        >
          <span class="ms-row-icon" slot="right-icon"></span>
        </van-field>
        <van-field
          :input-align="inputAlign"
          class="refrgtAreaName"
          v-if="infoReg.hasOwnProperty('rgtAreaName')"
          @click="showPopAction('address', 'rgtName', [])"
          :value="userInfo.rgtAreaName"
          label="户籍"
          type="textarea"
          rows="1"
          autosize
          readonly
          placeholder="请选择"
          @focus="tipsInfo.rgtAreaName = ''"
          :error="tipsInfo.rgtAreaName !== ''"
        >
          <span class="ms-row-icon" slot="right-icon"></span>
        </van-field>
        <van-field
          :input-align="inputAlign"
          class="refzipCode"
          v-if="infoReg.hasOwnProperty('zipCode')"
          v-model="userInfo.zipCode"
          label="邮政编码"
          type="number"
          maxlength="6"
          clearable
          placeholder="请输入"
          @focus="tipsInfo.zipCode = ''"
          :error="tipsInfo.zipCode !== ''"
        />

        <template v-if="infoReg.hasOwnProperty('postalAreaName')">
          <van-field
            :input-align="inputAlign"
            class="refpostalAreaName"
            @click-input="showPopAction('address', 'postalAreaName', [])"
            :value="userInfo.postalAreaName"
            type="textarea"
            rows="1"
            autosize
            readonly
            label-width="130px"
            placeholder="请选择"
            @focus="tipsInfo.postalAreaName = ''"
            :error="tipsInfo.postalAreaName !== ''"
          >
            <div slot="label" class="flexlabel">
              <div class="mr5">通讯地址</div>
              <div
                class="same_to_btn"
                :class="postSameHome ? 'is_same_res' : ''"
                @click.stop="setPostalToJuZhu(postSameHome == 1 ? '' : 1)"
                v-if="infoReg.hasOwnProperty('areaName')"
              >
                同居住地
              </div>
            </div>
            <span class="ms-row-icon" slot="right-icon"></span>
          </van-field>
        </template>
        <van-field
          :input-align="inputAlign"
          class="refpostalPermanentAddress"
          v-if="infoReg.hasOwnProperty('postalPermanentAddress')"
          v-model="userInfo.postalPermanentAddress"
          label="详细地址"
          :readonly="postSameHome == 1"
          type="textarea"
          rows="1"
          maxlength="30"
          autosize
          clearable
          :placeholder="`必须包含:${detailAddrRule}`"
        />
        <van-field
          class="refpostalZipCode"
          v-if="infoReg.hasOwnProperty('postalZipCode')"
          v-model="userInfo.postalZipCode"
          label="邮政编码"
          :readonly="postSameHome == 1"
          type="number"
          maxlength="6"
          clearable
          placeholder="请输入"
          @focus="tipsInfo.postalZipCode = ''"
          :error="tipsInfo.postalZipCode !== ''"
        />
        <van-field
          :input-align="inputAlign"
          class="refhomeAreaName"
          @click-input="showPopAction('address', 'homeAreaName', [])"
          :value="userInfo.homeAreaName"
          type="textarea"
          rows="1"
          autosize
          readonly
          label-width="130px"
          placeholder="请选择"
          @focus="tipsInfo.homeAreaName = ''"
          :error="tipsInfo.homeAreaName !== ''"
          v-if="infoReg.hasOwnProperty('homeAreaName')"
        >
          <div slot="label" class="flexlabel">
            <div class="mr5">家庭地址</div>
            <div
              class="same_to_btn"
              :class="homeSamePostal ? 'is_same_res' : ''"
              @click.stop="setHomeToPostal(homeSamePostal == 1 ? '' : 1)"
              v-if="infoReg.hasOwnProperty('postalAreaName')"
            >
              同通讯地
            </div>
          </div>
          <span class="ms-row-icon" slot="right-icon"></span>
        </van-field>
        <van-field
          :input-align="inputAlign"
          class="refhomePermanentAddress"
          v-if="infoReg.hasOwnProperty('homePermanentAddress')"
          v-model="userInfo.homePermanentAddress"
          label="详细地址"
          :readonly="homeSamePostal == 1"
          type="textarea"
          rows="1"
          maxlength="30"
          autosize
          :placeholder="`必须包含:${detailAddrRule}`"
        />
        <div class="van-cell extro" v-if="infoReg.hasOwnProperty('email')">
          <van-field
            :input-align="inputAlign"
            class="refemail"
            v-model="userInfo.email"
            @input="showEmailAppend = true"
            @blur="hideAppend"
            @focus="
              tipsInfo.email = '';
              showEmailAppend = true;
            "
            label="邮箱"
            type="email"
            clearable
            placeholder="请输入"
            :error="tipsInfo.email !== ''"
          >
          </van-field>
          <div class="hintBox" v-if="emails.length > 0 && showEmailAppend">
            <div
              @click="userInfo.email = mail"
              class="hintItem"
              v-for="mail in emails"
              :key="mail"
            >
              {{ mail }}
            </div>
          </div>
        </div>
        <!-- 学历 -->
        <van-field
          label="学历"
          class="refdegree"
          :input-align="inputAlign"
          @click="
            tipsInfo.degree = '';
            showPopAction('picker', 'degree', degreeList, userInfo.degree);
          "
          :value="userInfo.degreeName"
          readonly
          placeholder="请选择"
          @focus="tipsInfo.degree = ''"
          :error="tipsInfo.degree !== ''"
          v-if="infoReg.hasOwnProperty('degree')"
        >
          <span
            class="ms-row-icon"
            slot="right-icon"
            v-if="degreeList.length > 1"
          ></span>
        </van-field>
        <!-- 婚姻状况  -->
        <van-field
          class="refmaritalStatus"
          :input-align="inputAlign"
          @click="
            showPopAction(
              'picker',
              'maritalStatus',
              maritalStatusList,
              userInfo.maritalStatus
            )
          "
          :value="userInfo.maritalStatusName"
          label="婚姻状况"
          readonly
          placeholder="请选择"
          v-if="infoReg.hasOwnProperty('maritalStatus')"
        >
          <span
            class="ms-row-icon"
            slot="right-icon"
            v-if="maritalStatusList.length > 1"
          ></span>
        </van-field>
        <van-field
          :input-align="inputAlign"
          class="refresidentType"
          v-if="infoReg.hasOwnProperty('residentType')"
          @click="showPopAction('picker', 'residentType', residentTypeList)"
          :value="userInfo.residentTypeName"
          label="居民类型"
          readonly
          placeholder="请选择"
        >
          <span
            class="ms-row-icon"
            slot="right-icon"
            v-if="residentTypeList.length > 1"
          ></span>
        </van-field>
        <van-field
          :input-align="inputAlign"
          class="refsocialInsuFlag"
          :class="{ disEditModel: disEditFields }"
          label="是否有社保"
          readonly
          @focus="tipsInfo.socialInsuFlag = ''"
          :error="tipsInfo.socialInsuFlag !== ''"
          v-if="infoReg.hasOwnProperty('socialInsuFlag')"
        >
          <template #input>
            <MsRadios
              :curVal="userInfo.socialInsuFlag"
              :arrList="socialSecList"
              type="socialInsuFlag"
              @change="changeMsRadio"
            />
          </template>
        </van-field>
        <!-- 个人收入来源-->
        <template v-if="infoReg.hasOwnProperty('incomeSource')">
          <van-field
            :input-align="inputAlign"
            class="refincomeSource"
            label="收入来源"
            readonly
            @focus="tipsInfo.incomeSource = ''"
            :error="tipsInfo.incomeSource !== ''"
          >
            <template #input>
              <IncomeSource
                v-model="userInfo.incomeSource"
                fieldKey="incomeSource"
                :arrList="IncSourceList"
                @clickEvent="changeData"
              >
              </IncomeSource>
            </template>
          </van-field>
        </template>
        <template v-if="infoReg.hasOwnProperty('otherCompanyCompIns')">
          <van-field
            class="refotherCompanyCompIns"
            :input-align="inputAlign"
            label-width="235px"
            label="是否有其他公司费用补偿型医疗险"
            readonly
            @focus="tipsInfo.otherCompanyCompIns = ''"
            :error="tipsInfo.otherCompanyCompIns !== ''"
          >
            <template #input>
              <MsRadios
                :curVal="userInfo.otherCompanyCompIns"
                :arrList="yesNoCheckList"
                type="otherCompanyCompIns"
                @change="changeMsRadio"
              />
            </template>
          </van-field>
        </template>
        <!-- 阳光新增字段 -->
        <!-- 子女个数 -->
        <van-field
          label="子女个数"
          class="refchildrenNum"
          v-model="userInfo.childrenNum"
          :input-align="inputAlign"
          type="number"
          clearable
          placeholder="请输入"
          :error="tipsInfo.childrenNum !== ''"
          @input="tipsInfo.childrenNum = ''"
          @focus="tipsInfo.childrenNum = ''"
          maxlength="2"
          v-if="infoReg.hasOwnProperty('childrenNum')"
        >
        </van-field>
        <!-- 家庭年收入 -->
        <van-field
          label="家庭年收入"
          class="reffamilyIncome"
          :value="userInfo.familyIncome"
          type="number"
          :input-align="inputAlign"
          placeholder="请输入"
          @input="(e) => (userInfo.familyIncome = money(e))"
          @focus="tipsInfo.familyIncome = ''"
          @blur="testFamIncom"
          :error="tipsInfo.familyIncome !== ''"
          v-if="infoReg.hasOwnProperty('familyIncome')"
        >
          <template #button>
            <span class="field_unit">万元</span>
          </template>
        </van-field>
        <!-- 家庭收入来源-->
        <template v-if="infoReg.hasOwnProperty('familyIncomeSource')">
          <van-field
            :input-align="inputAlign"
            class="reffamInSoc"
            label="家庭收入来源"
            readonly
            @focus="tipsInfo.famInSoc = ''"
            :error="tipsInfo.famInSoc !== ''"
          >
            <template #input>
              <MultiSpanRadio
                :curVal="userInfo.familyIncomeSource"
                fieldKey="familyIncomeSource"
                :arrList="IncSourceList"
                @clickEvent="changeData"
              >
              </MultiSpanRadio>
            </template>
          </van-field>
        </template>
        <van-field
          :input-align="inputAlign"
          class="refcrsIdType"
          v-if="infoReg.hasOwnProperty('crsIdType')"
          @click="openCrsIdType"
          :value="userInfo.crsIdTypeName"
          label-width="120px"
          readonly
          placeholder="请选择"
          @focus="tipsInfo.crsIdType = ''"
          :error="tipsInfo.crsIdType !== ''"
        >
          <div slot="label" class="flex_ac">
            <span>个税居民类型</span>
            <FieldDescMode field="crsIdType" />
          </div>
          <span
            class="ms-row-icon"
            slot="right-icon"
            v-if="hasResidentFile || crsIdTypeList.length > 1"
          ></span>
        </van-field>
      </div>
    </div>
    <van-popup v-model="showPop" round position="bottom">
      <van-picker
        v-if="popConfig.type == 'picker'"
        ref="picker"
        show-toolbar
        :columns="viewOptions"
        @confirm="onConfirmPick"
        @cancel="showPop = false"
        :default-index="defaultIndex"
      >
        <div slot="title" class="keyBox" v-if="popConfig.list.length > 8">
          <input
            type="text"
            class="keyInput"
            placeholder="请输入关键字查询"
            v-model="keyWord"
          />
        </div>
      </van-picker>
      <van-datetime-picker
        v-else-if="popConfig.type == 'date'"
        :value="currentDate"
        :min-date="minDate"
        :max-date="maxDate"
        type="date"
        @confirm="onConfirmDate"
        @cancel="showPop = false"
      />
      <OccupationPop
        v-else-if="popConfig.type == 'job'"
        utype="tbr"
        @cancel="showPop = false"
        @confirm="onConfirmDJob"
      />
      <Address
        v-else-if="popConfig.type == 'address'"
        :filterCode="filterCode"
        @cancle="showPop = false"
        @addresssConfirm="addresssConfirm"
      />
    </van-popup>
    <CustomerDirectory
      v-if="showUserList"
      :ref="`${userFlag}CustomerDirectory`"
      @confirm="sureUserSelect"
      @cancel="showUserList = false"
    />
    <OcrRecoganizePop
      :showOcrPop="showSheet"
      ocrType="tbr"
      @sureBtn="sureOcrRes"
      v-if="showSheet"
    >
    </OcrRecoganizePop>
    <van-popup v-model="showFile" round position="bottom" style="height: 80vh">
      <RevenueFile
        uType="tbr"
        v-if="revenueFileType == '1'"
        :fileInfo="userInfo.taxIdentInfo"
        :infoData="userInfo"
        @handleFile="handleFile"
      />
      <Revenue2File
        uType="tbr"
        v-else-if="revenueFileType == '2'"
        :fileInfo="userInfo.taxIdentInfo"
        :infoData="userInfo"
        @handleFile="handleFile"
      />
    </van-popup>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import MultiSpanRadio from "@/components/MultiSpanRadio";
import RevenueFile from "./RevenueFile";
import Revenue2File from "./Revenue2File";
import FieldDescMode from "./FieldDescMode";
import IncomeSource from "./IncomeSource";
import SmsCodeBtn from "./SmsCodeBtn";
import { userInfoMix } from "@/mixins/userInfo";
import { radioMixin } from "@/mixins/radios";
import { popupMixin } from "@/mixins/popup";
import { smsCodeMixin } from "@/mixins/smscode";
import { tbrBbrMixin } from "@/mixins/tbrbbr";
import { validUserInfo } from "@/translate/validate/customer";

export default {
  name: "Step2Applicant",
  components: {
    SmsCodeBtn,
    RevenueFile,
    Revenue2File,
    IncomeSource,
    FieldDescMode,
    MultiSpanRadio,
  },
  computed: {
    ...mapGetters({
      idTypeList: "dictionary/applicantIdTypeList",
      provinceNo: "agent/saleProvinceNo",
      showedRisks: "risks/showedRisks",
      provinceFilter: "dictionary/provinceFilter",
      IncSourceList: "dictionary/IncSourceList",
      tbBirthStrMin: "infoReg/tbBirthMin",
      tbBirthStrMax: "infoReg/tbBirthMax",
      shuangLuAge: "page/shuangLuAge",
      totalPrem: "insert/totalPrem",
      slPreWarn: "common/slPreWarn",
    }),
    infoReg() {
      return JSON.parse(JSON.stringify(this.inputReg.applicant));
    },
    filterProvince() {
      if (this.provinceFilter) {
        return this.provinceNo;
      }
      return "";
    },
    // hasSameBbr() {
    //   let res = false;
    //   if (this.bbrMultList.length > 0) {
    //     const obj = this.bbrMultList.find(
    //       (e) => e.idNum == this.userInfo.idNum
    //     );
    //     if (obj) {
    //       res = true;
    //     }
    //   }
    //   return res;
    // },
  },
  watch: {
    userInfo: {
      handler: function (val) {
        if (this.pageLoad) {
          this.$store.commit("insert/UPDATE_APPLICANT", val);
        }
      },
      deep: true,
    },
  },
  data() {
    return {
      userType: "投保人",
      userFlag: "tbr0",
      userInfo: {},
      refChildrenNum: "",
      reffamilyIncomeLevel: "",
      reffamInSoc: "",
    };
  },
  mixins: [userInfoMix, radioMixin, popupMixin, tbrBbrMixin, smsCodeMixin],
  created() {
    const tbtItem = this.applicant;
    Object.keys(this.userInfo).map((key) => {
      if (tbtItem.hasOwnProperty(key)) {
        this.userInfo[key] = tbtItem[key];
      }
    });
    // Object.assign(this.userInfo, this.applicant);
    this.initDefaultData();
    this.$nextTick(() => {
      this.pageLoad = true;
    });
  },
  methods: {
    async saveForm() {
      // 根据证件号查询是否已存在承保保单并验证姓名
      let applicant = this.userInfo;
      // console.log('saveForm---1', this.userInfo);
      this.$store.commit("insert/UPDATE_APPLICANT", applicant);
      const iptCfg = JSON.parse(JSON.stringify(this.infoReg));
      let res = validUserInfo(iptCfg, applicant, "投保人");
      if (res.status == false) {
        let id = "ref" + res.target;
        let target = document.querySelector("." + id);
        this.tipsInfo[res.target] = res.msg;
        if (target) {
          target.scrollIntoView({
            behavior: "smooth",
            block: "center",
          });
        }
        // this.$toast(`投保人规则校验：${res.msg}`);
        this.$store.commit("common/SET_FIELD_MEAN_CONT", {
          label: `投保人规则校验`,
          desc: `${res.msg}`,
        });
      }
      // 验证码校验
      if (this.infoReg.hasOwnProperty("validCode") && res.status) {
        res = await this.checkSmsCode();
        if (res.status) {
          this.$store.dispatch(
            "common/checkedSmsPhone",
            `${this.userInfo.phone}${this.userInfo.validCode}${this.userFlag}`
          );
        }
      }
      return res;
    },
    testFamIncom() {
      const pInc = this.userInfo.income * 1,
        fInc = this.userInfo.familyIncome * 1;
      // console.log(pInc, fInc)
      if (fInc < pInc) {
        this.$msAlert(
          `家庭年收入不得小于投保人年收入，提交后可能会进入人工核保，请仔细核对填写的信息`
        );
      }
    },
    doubleInputs(birthDate) {
      const uage = this.$GlobalFuns.userAge(`${birthDate}`);
      this.$store.commit(
        "common/SET_SL_PRE_WARN",
        Number(uage) >= this.shuangLuAge
      );
      if (Number(uage) >= this.shuangLuAge) {
        this.$dialog
          .alert({
            title: "双录提示",
            message:
              "根据地区监管规定,此投保申请须双录（同步进行录音、录像）,请联系业务员使用《WE易保》投保和双录。",
            messageAlign: "left",
            confirmButtonColor: "#DA251E",
            confirmButtonText: "我已知晓",
            getContainer: "body",
          })
          .then(() => {
            // 申请打款
            this.applyDefry();
          });
      }
    },
    applyDefry() {
      this.$http
        .post(
          "/ms-insure/api/bilaiduo/applyDaKuan",
          {
            workNum: this.workNum,
            userId: this.bldUserId,
            money: this.totalPrem,
          },
          {
            showDialog: false,
            json: true,
          }
        )
        .then((res) => {
          // console.log(res);
        });
    },
    noAuthHandle() {
      if (this.slPreWarn) {
        this.$store.commit("common/SET_FIELD_MEAN_CONT", {
          label: `双录提示`,
          desc: `根据地区监管规定,此投保申请须双录（同步进行录音、录像）,请联系业务员使用《WE易保》投保和双录。`,
        });
      }
    },
  },
};
</script>
<style lang="less" scoped>
@import "../style.less";
/deep/.van-button--small {
  height: 26px;
}
</style>
